/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved.
*
*  This file is part of the GroupMe! Project. Source code of 
*  this project is closed and redistribution of this code is
*  prohibited. 
*  
*  Contact: http://www.groupme.net
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.search.strategy.model;

import java.util.Comparator;


/**
 * created on Jul 4, 2007
 * 
 * Simple {@link Comparator} implementation to compare {@link WeightedResource} instances.
 * 
 * @author Fabian Abel, <a href="mailto:abel@l3s.de">abel@l3s.de</a>
 * @author last edited by: $Author: fabian $
 * 
 * @version $Revision: 1.2 $ $Date: 2008-01-14 15:05:08 $
 */
public class WeightedIdentifiableComparatorByWeight implements Comparator<AbstractWeightedIdentifiable> {

	/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(AbstractWeightedIdentifiable a, AbstractWeightedIdentifiable b) {
		if(Double.isNaN(a.getWeight()) || Double.isNaN(b.getWeight())){
			if(Double.isNaN(a.getWeight()) && Double.isNaN(b.getWeight())){
				return 0;
			}else if(Double.isNaN(a.getWeight())){
				return 1;
			}else{
				return -1;
			}
		}else if(a.getWeight() == b.getWeight()){
			return 0;
		}else if(a.getWeight() < b.getWeight()){
			return 1;
		}else{
			return -1;
		}
	}



}
